package com.hq.door.dto;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import com.hq.door.pojo.TClass;

public class DClassDto {
	public static DClass writeMajor(TClass tClass){
		DClass dClass = new DClass();
	    if (tClass != null){
	    	dClass.setId(tClass.getId());
	    	dClass.setName(tClass.getName());
	    	dClass.setCode(tClass.getCode());
	    	dClass.setGrade(tClass.getGrade());
	    	dClass.setMajorname(tClass.getTMajor().getName());
	    	if(tClass.getTTeacher()!=null){
	    		dClass.setTeachername(tClass.getTTeacher().getName());
	    	}
	    	dClass.setInstitutename(tClass.getTMajor().getTInstitute().getName());
	    	dClass.setModifiedTime(tClass.getModifiedTime());
	    	dClass.setModifiedBy(tClass.getModifiedBy());
	    }
	    return dClass;
    }
	
	
	public static DClass[] writeMajor(Collection classes){
		List list = new ArrayList();
		if (classes != null){
			Iterator iterator = classes.iterator();
            while (iterator.hasNext())
            {
                list.add(writeMajor((TClass) iterator.next()));
            }
		}
		DClass[] array = new DClass[list.size()]; 
		return (DClass[]) list.toArray(array);
	}

	public static TClass readMajor(DClass dClass){
		TClass tClass = new TClass();
	    if (dClass != null){
	    	tClass.setId(dClass.getId());
	    	tClass.setName(dClass.getName());
	    	tClass.setCode(dClass.getCode());
	    	tClass.setGrade(dClass.getGrade());
	    	tClass.setModifiedTime(dClass.getModifiedTime());
	    	tClass.setModifiedBy(dClass.getModifiedBy());
	    	
	    }
	    return tClass;
    }
}
